import { getUserInfoAPI } from '@/api/layout'
// 定义用户 子模块
const userModule = {
  namespaced: true,
  state () {
    return {
      token: '',
      userInfo: {}
    }
  },
  mutations: {
    setToken (state, tokenStr) {
      state.token = tokenStr
    },
    setUserInfo (state, userObj) {
      state.userInfo = userObj
    }
  },
  actions: {
    async getUserInfoAction (store) {
      // 调接口
      const { data: { data: userObj } } = await getUserInfoAPI()
      // 把后台返回的用户信息 通过 提交 setUserInfo 函数，
      // 完成对userInfo的赋值
      store.commit('setUserInfo', userObj)
    }
  }
}

// 导出用户 子模块
export default userModule
